import { request } from '@utils/http'
import { Key } from 'react'

import type { 
  getHosListRequestParamesType, 
  getHosListRequestReturnType, 
  addHosParamesType, 
  getHosListRequestReturnItemType, 
  updateHosParamesType 
} from './model/hospitalSetTypes'

// 查询医院列表
export const getHosListRequest = ({ page, limit, hosname, hoscode }: getHosListRequestParamesType) => {
  return request.get<any, getHosListRequestReturnType, any>(`/admin/hosp/hospitalSet/${page}/${limit}`, {
    params: {
      hosname,
      hoscode
    }
  })
}

// 添加医院
export const addHosRequest = (data: addHosParamesType) => {
  return request.post<any, null>('/admin/hosp/hospitalSet/save', data)
}

// 根据 id 查询医院数据
export const queryHosByIdRequest = (id: string) => {
  return request.get<getHosListRequestReturnItemType>(`/admin/hosp/hospitalSet/get/${id}`)
}

// 修改医院数据
export const updateHosRequest = (data: updateHosParamesType) => {
  return request.put<any, null>('/admin/hosp/hospitalSet/update', data)
}

// 删除医院数据
export const deleteHosRequest = (id: number) => {
  return request.delete(`/admin/hosp/hospitalSet/remove/${id}`)
}

// 批量删除医院数据
export const batchRemoveHospitalListRequest = (idList: Key[]) => {
  return request.delete<any, null>(`/admin/hosp/hospitalSet/batchRemove`, {
    // 注意请求参数
    // 如果是post/put可以直接写参数，但是get/delete要携带body参数必须这样写
    data: idList,
  });
}